﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qiang.Geometry
{
    public class LineString : Curve, ILineString
    {

        #region 初始化

        public LineString()
        { }

        public LineString(IList<Coordinate> coordinates)
            :base(coordinates)
        {
            _coordinates = coordinates;
        }


        #endregion


        #region ILineString成员函数

        /// <summary>
        /// 点数量。
        /// </summary>
        public int NumPoints
        {
            get { return _coordinates.Count; }
        }


        /// <summary>
        /// 获取index位置的点。
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public Coordinate GetPoint(int index)
        {
            return _coordinates[index];
        }


        #endregion


        #region Curve成员函数


        
        /// <summary>
        /// 是否为环。
        /// </summary>
        public override bool IsRing
        {
            get
            {
                if (IsClosed && IsSimple)
                    return true;
                return false;
            }
        }


        /// <summary>
        /// 计算长度。
        /// </summary>
        /// <returns></returns>
        protected override double ComputeLength()
        {
            return base.ComputeLength();
        }


        #endregion

        
        #region Geometry成员


        IList<Coordinate> _coordinates;

        /// <summary>
        /// 坐标集合。
        /// </summary>
        public override IList<Coordinate> Coordinates
        {
            get
            {
                return _coordinates;
            }
            set
            {
                _coordinates = value;
            }
        }

        /// <summary>
        /// 是否为空。
        /// </summary>
        public override bool IsEmpty
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// 是否为简单图形。
        /// </summary>
        public override bool IsSimple
        {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// 
        /// </summary>
        public override int Dimension
        {
            get { throw new NotImplementedException(); }
        }

        #endregion


        #region SQL

        /// <summary>
        /// 获取WKT描述.
        /// </summary>
        /// <returns></returns>
        public override string AsText()
        {
            string wktStr = "LINESTRING ( ";
            for (int i = 0; i < _coordinates.Count; i++)
            {
                wktStr += _coordinates[i].X + " " + _coordinates[i].Y + " " + _coordinates[i].Z + " " + _coordinates[i].M;
                if (i != _coordinates.Count - 1)
                {
                    wktStr += ", ";
                }
                else
                {
                    wktStr += " )";
                }
            }
            return wktStr;
        }

        /// <summary>
        /// 获取WKB描述.
        /// </summary>
        /// <returns></returns>
        public override byte[] AsBinarry()
        {
            throw new NotImplementedException();
        }


        #endregion

    }
}
